
<?php
	include('connect.php');
	require_once("PHPMailer/sendmail.php");
	ini_set('display_errors', '0');
	$email_result = mysql_query("SELECT * FROM users_newsletters u LEFT JOIN users_emails n ON u.email_id=n.email_id LEFT JOIN  newsletters w ON u.news_id=w.news_id WHERE u.status='0' ORDER BY user_news_id");
	while ( $rows = mysql_fetch_array($email_result)){
		$subject=$rows['title'];
		$to=$rows['email'];
		$msg=$rows['content'].'<a target="_blank" href="http://'.$_SERVER['HTTP_HOST'].'/newsletteraapthi/unsubscribe.php?email='.base64_encode($to).'">Unsubscribe</a>';
		echo $msg;exit;
		$headers = "MIME-Version: 1.0" . "\r\n";
		$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
		$headers .= 'From: <info@aapthitech.com>' . "\r\n";
		if(sendMail($to,$subject,$msg,$headers))
		{
			$sql="UPDATE users_newsletters SET status='1' where user_news_id='".$rows['user_news_id']."'";
			echo "1";
		}else
		{
			echo "0";
		}
	}
?>